from __future__ import annotations

from dataclasses import dataclass
from math import pi


@dataclass
class AnchorBoltDesign:
    embedment_depth_mm: float
    pullout_capacity_kN: float
    shear_capacity_kN: float
    note: str


def design_anchor_bolt(diameter_mm: int, concrete_strength_MPa: float, steel_yield_MPa: float, required_tension_kN: float, edge_distance_mm: float = 150.0, spacing_mm: float = 200.0) -> AnchorBoltDesign:
    """地脚螺栓设计（简化）：
    - 抗拔承载力 ~ π·d·l·τ ，τ取混凝土抗拉强度0.6√f_ck
    - 抗剪承载力 ~ 0.6·A_s·f_y
    - 计算所需埋深以满足抗拔
    """

    import math
    d = diameter_mm / 1000.0
    tau = 0.6 * math.sqrt(max(0.0, concrete_strength_MPa))  # MPa
    # 求 l 使 π d l τ ≥ N(kN) -> N*1000 ≤ π d l τ (MPa->kN/mm2)
    required_l_mm = (required_tension_kN * 1000.0) / max(1e-6, math.pi * diameter_mm * tau / 1000.0)
    shear_capacity = 0.6 * (math.pi * (diameter_mm ** 2) / 4.0) * steel_yield_MPa / 1000.0
    pullout_capacity = math.pi * diameter_mm * max(required_l_mm, 8 * diameter_mm) * tau / 1000.0
    return AnchorBoltDesign(embedment_depth_mm=max(required_l_mm, 8 * diameter_mm), pullout_capacity_kN=pullout_capacity, shear_capacity_kN=shear_capacity, note="需按混凝土破坏锥与边距修正")


